package stripesbook.action.user;

import java.util.Collection;
import org.stripesbook.rayures.view.ViewObject;
import org.stripesbook.rayures.view.stripes.SLink;
import org.stripesbook.rayures.view.stripes.SUrl;
import stripesbook.action.MockDataLoaderActionBean;
import stripesbook.model.Contact;
import stripesbook.view.ContactTable;

public class ContactListView extends ViewObject<ContactListView> {
  private Collection<Contact> contacts;

  public ContactListView init(Collection<Contact> contacts) {
    this.contacts = contacts;
    return getThis();
  }

  public Collection<Contact> getContacts() {
    return contacts;
  }

  public SLink getCreateContactLink() {
    return tag(SLink.class).beanclass(ContactFormActionBean.class)
      .onclick("return ajaxLink(this, '#contact_form');")
      .label(bundle.get("createNewContact"));
  }

  public SUrl getFilterContactsUrl() {
    return tag(SUrl.class).beanclass(ContactListActionBean.class);
  }

  public Object getContactTable() {
    return tag(ContactTable.class).init(contacts);
  }

  public SLink getLoadMockContactsLink() {
    return tag(SLink.class).beanclass(MockDataLoaderActionBean.class)
      .event("loadMockContacts");
  }
}
